package com.ruoyi.project.monitor.tarsmonitor.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.monitor.tarsmonitor.domain.TarsMonitor;
import com.ruoyi.project.monitor.tarsmonitor.service.ITarsMonitorService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * tars监控Controller
 * 
 * @author shixiangwen
 * @date 2020-03-23
 */
@Controller
@RequestMapping("/monitor/tarsmonitor")
public class TarsMonitorController extends BaseController
{
    private String prefix = "monitor/tarsmonitor";

    @Autowired
    private ITarsMonitorService tarsMonitorService;

    @RequiresPermissions("monitor:tarsmonitor:view")
    @GetMapping()
    public String tarsmonitor()
    {
        return prefix + "/tarsmonitor";
    }

    /**
     * 查询tars监控列表
     */
    @RequiresPermissions("monitor:tarsmonitor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TarsMonitor tarsMonitor)
    {
        startPage();
        List<TarsMonitor> list = tarsMonitorService.selectTarsMonitorList(tarsMonitor);
        return getDataTable(list);
    }

    /**
     * 导出tars监控列表
     */
    @RequiresPermissions("monitor:tarsmonitor:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TarsMonitor tarsMonitor)
    {
        List<TarsMonitor> list = tarsMonitorService.selectTarsMonitorList(tarsMonitor);
        ExcelUtil<TarsMonitor> util = new ExcelUtil<TarsMonitor>(TarsMonitor.class);
        return util.exportExcel(list, "tarsmonitor");
    }

    /**
     * 新增tars监控
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存tars监控
     */
    @RequiresPermissions("monitor:tarsmonitor:add")
    @Log(title = "tars监控", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TarsMonitor tarsMonitor)
    {
        return toAjax(tarsMonitorService.insertTarsMonitor(tarsMonitor));
    }

    /**
     * 修改tars监控
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TarsMonitor tarsMonitor = tarsMonitorService.selectTarsMonitorById(id);
        mmap.put("tarsMonitor", tarsMonitor);
        return prefix + "/edit";
    }

    /**
     * 修改保存tars监控
     */
    @RequiresPermissions("monitor:tarsmonitor:edit")
    @Log(title = "tars监控", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TarsMonitor tarsMonitor)
    {
        return toAjax(tarsMonitorService.updateTarsMonitor(tarsMonitor));
    }

    /**
     * 删除tars监控
     */
    @RequiresPermissions("monitor:tarsmonitor:remove")
    @Log(title = "tars监控", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tarsMonitorService.deleteTarsMonitorByIds(ids));
    }
}
